//
//  LCShowComposeViewModel.m
//  JKBiblicalReading
//
//  Created by admin on 2018/8/18.
//  Copyright © 2018年 LC. All rights reserved.
//  处理数据, 协管,加载网络下载数据

#import "LCShowComposeViewModel.h"

@implementation LCShowComposeViewModel

- (void)getComposeTextDataWithType:(NSInteger)type shengJingTitle:(NSString *)shengJingTitle notesContentArr:(NSArray *)notesContentArr success:(void (^)(NSDictionary *))successBlock failure:(void (^)(NSError *))failureBlock  end:(void (^)(void))endBlock{
        NSString *chapter = [shengJingTitle substringWithinBoundsLeft:@"第" right:@"章"];
        NSString *book = [shengJingTitle substringWithinBoundsLeft:@"约" right:@"("];
        NSString *tag = [LCUtils getTagWithNotesContentArr:notesContentArr shengJingTitle:shengJingTitle];
    
        NSString *urlString = [NSString stringWithFormat:@"%@%@"
                               ,http_zongSJUrl,@"/bible/lists"
                               ];
        if (1) {
            NSLog(@"urlString = %@", urlString);
        }
        //   可选参数    @"fuid": [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"],
    
        NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                      @(type), @"type",
                                      book, @"book",
                                      chapter, @"chapter",
                                      tag, @"tag",
                                      @(self.page), @"page",
                                      @"30", @"size",
                                      nil];
    
        NSMutableDictionary *parameters
        = [NSMutableDictionary dictionaryWithDictionary:myDictionary];
    
        [[NetworkTool sharedInstance] POSTFuYinWithUrlString:urlString input:parameters success:^(NSDictionary *dict) {
            NetWorkModel *netWorkModel = [NetWorkModel yy_modelWithJSON:dict];
            if(netWorkModel.status == 1){
                
                NSArray<LCShowComposeModel *> *array = [NSArray yy_modelArrayWithClass:[LCShowComposeModel class] json:netWorkModel.data];
                if (self.page > 1) {
                    [self.dataArray addObjectsFromArray:array];
                }else{
                    self.dataArray = array.mutableCopy;
                }
                if (array.count > 0) {
                    if (successBlock) {
                        successBlock(dict);
                    }
                }else{
                    if (endBlock) {
                        endBlock();
                    }
                }
            }else{
                if (failureBlock) {
                    failureBlock(nil);
                }
                [SVProgressHUD showErrorWithStatus:netWorkModel.msg];
            }
        } failure:^(NSError *error) {
            if (failureBlock) {
                failureBlock(error);
            }
        }];
}

- (NSMutableArray<LCShowComposeModel *> *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

//#pragma mark - 关注
//+ (void)clickButFocusOnDetaill :(NSString *)uid :(NSString *)isUndo success:(void (^)(void))successBlock failure:(void (^)(NSString *str))failureBlock
//{
//    if([[_UserM usercode] isEqualToString:@""]){
//        pushAccLoginNotification
//        if (failureBlock) {
//            failureBlock(@"未登录");
//        }
//        [SVProgressHUD showErrorWithStatus:@"未登录"];
//    }else{
//        [LSZRequestData payAttentionToOthers:uid Ck:@"0" mode:isUndo :^(BOOL isOk, NSString * str, NSDictionary * dic) {
//            if (isOk == YES) {
//                if (successBlock) {
//                    successBlock();
//                }
//                [SVProgressHUD showSuccessWithStatus:@"关注成功!"];
//            }else{
//                if (failureBlock) {
//                    failureBlock(str);
//                }
//                [SVProgressHUD showErrorWithStatus:str];
//            }
//        }];
//    }
//}

#pragma mark - 点赞
//    {
//        "tid": "0",
//        "type": "1",
//        "ck": "0",
//        "mode": "0"
//    }
+ (void)clickZanButWithTid:(NSString *)tid type:(NSString *)type mode:(NSString *)mode success:(void (^)(void))successBlock failure:(void (^)(NSError *error))failureBlock
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVCNotification;
        return;
    }
    NSString *urlString = [NSString stringWithFormat:@"%@%@"
                           ,http_zongSJUrl,@"/bible/admire"
                           ];
    if (1) {
        NSLog(@"urlString = %@", urlString);
    }
    //   可选参数    @"fuid": [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"],
    NSDictionary *myDictionary = [NSDictionary dictionary];
    myDictionary = @{@"tid" : tid,
                     @"type" : @"1",
                     @"ck" : @"0",
                     @"mode" : mode};
    NSMutableDictionary *parameters
    = [NSMutableDictionary dictionaryWithDictionary:myDictionary];
    
    [[NetworkTool sharedInstance] POSTFuYinWithUrlString:urlString input:parameters success:^(NSDictionary *dict) {
        NetWorkModel *netWorkModel = [NetWorkModel yy_modelWithJSON:dict];
        if(netWorkModel.status == 1){
            if (successBlock) {
                successBlock();
            }
            [SVProgressHUD showSuccessWithStatus:netWorkModel.msg];
        }else{
            NSError *error;
            if (failureBlock) {
                failureBlock(error);
            }
        }
    } failure:^(NSError *error) {
        if (failureBlock) {
            failureBlock(error);
        }
    }];


}


@end
